package com.wky1.wang1.Controller;

import com.wky1.wang1.AliyunOss.AliyunOSSutils;
import com.wky1.wang1.Request;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Slf4j
@RequestMapping("/w")
@RestController
public class wenjianController {
    @Autowired
    private AliyunOSSutils aliyunOSSutils;
    @PostMapping("/wkyxxy")
    public Request upload(MultipartFile image){
        //获取文件的原始文件名
        String Filename=image.getOriginalFilename();
        //创建新的文件名
        String newFilename= UUID.randomUUID().toString()+Filename.substring(Filename.lastIndexOf("."));
        try {
        //将文件保存在服务器端 C:\位置下
            image.transferTo(new File("C:\\"+newFilename));
        } catch (IOException e) {
            e.printStackTrace();
        }
          return Request.success();
    }


    @PostMapping("/upload")
    public Request uypload(MultipartFile image) throws IOException {
        String url=aliyunOSSutils.upload(image);
        return Request.success(url);
    }


}
